package com.bjsxt.service.imp;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;

import com.bjsxt.commons.DataGridModel;
import com.bjsxt.mapper.UsersMapper;
import com.bjsxt.pojo.Drug;
import com.bjsxt.pojo.Users;
import com.bjsxt.pojo.UsersExample;
import com.bjsxt.service.UserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

/**
 * 
 * @author clw
 *	用户管理的增删查改
 */

@Service
public class UserServiceImpl implements UserService {
	
	@Autowired
	private UsersMapper userMapper;
	
	/**
	 * 完成添加用户信息的功能
	 */
	public void addUser(Users user) {
		this.userMapper.insertSelective(user);
	}

	/**
	 * 完成查询所有用户信息的功能
	 */
	public DataGridModel showUsers(Integer page, Integer rows) {
		//调用分页插件进行分页
		PageHelper.startPage(page, rows);
		UsersExample ue = new UsersExample();
		List<Users> list = this.userMapper.selectByExample(ue);
		//获取总条数
		PageInfo<Users> pt = new PageInfo<>(list);
		long total = pt.getTotal();
		
		DataGridModel dgm = new DataGridModel();
		dgm.setTotal(total);
		dgm.setRows(list);
		return dgm;
	}

	/**
	 * 完成删除用户的功能
	 */
	public void dropUser(int userid) {
		this.userMapper.deleteByPrimaryKey(userid);
	}

	/**
	 * 完成对用户信息的更新
	 */
	public void updateUser(Users user) {
		this.userMapper.updateByPrimaryKey(user);
	}
	
}
